<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>滇宏教育-跟新用户信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <blockquote class="layui-elem-quote layui-text">
           Nothing is ok
        </blockquote>

        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>修改用户</legend>
        </fieldset>

        <form class="layui-form" action="/manager2/user/realUpdate">
            <div class="layui-form-item">
                <label class="layui-form-label">用户名</label>
                <div class="layui-input-block">
                    <input type="hidden" name="uid" lay-verify="title" autocomplete="off" placeholder="请输入用户名" class="layui-input" value="null">
                    <input type="text" name="username" id="username" lay-verify="title" autocomplete="off" placeholder="请输入用户名"  class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">用户密码</label>
                <div class="layui-input-inline">
                    <input type="password" name="password" id="password" lay-verify="pass" placeholder="请输入密码" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">请填写6到12位密码</div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">用户身份</label>
                <div class="layui-input-block">:
                    <input type="checkbox" id="super" name="type" title="超级管理员" value="7" >
                    <input type="checkbox" id="c" name="type" title="语文老师" value="1">
                    <input type="checkbox" id="m" name="type" title="数学老师" value="2">
                    <input type="checkbox" id="e" name="type" title="英语老师" value="3">
                    <input type="checkbox" id="che" name="type" title="化学老师" value="4">
                    <input type="checkbox" id="ph" name="type" title="物理老师" value="5">
                    <input type="checkbox" id="bio" name="type" title="生物老师" value="6">
                </div>
            </div>


            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>

        <!-- 示例-970 -->
        <ins class="adsbygoogle" style="display:inline-block;width:970px;height:90px" data-ad-client="ca-pub-6111334333458862" data-ad-slot="3820120620"></ins>





    </div>
</div>

<script src="../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="../../js/jquery-1.11.3.min.js"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    $(function () {
        $.ajax({
            url:'../../user/single',
            success:function (msg) {
                $('#username').val(msg.username);
                $('#password').val(msg.password);
                //alert(msg.type);
                var form1 = JSON.stringify(msg.type)
                var form2 = form1.substring(1,form1.length-1);
                var form3 = form2.substring(0,form2.length-1);
                var strings = form3.split(",");
                for(var i= 0;i<strings.length;i++){

                    if (strings[i] == '7'){
                        $('#super').attr("checked",true);
                    }
                    if (strings[i] == '1'){
                        $('#c').attr("checked",true);
                    }
                    if (strings[i] == '2'){
                        $('#m').attr("checked",true);
                    }
                    if (strings[i] == '3'){
                        $('#e').attr("checked",true);
                    }
                    if (strings[i] == '4'){
                        $('#che').attr("checked",true);
                    }
                    if (strings[i] == '5'){
                        $('#ph').attr("checked",true);
                    }
                    if (strings[i] == '6'){
                        $('#bio').attr("checked",true);
                    }
                }



            },error:function () {
                alert('权限不足');
            }

        })
    })


    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;

        //日期
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date1'
        });

        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');

        //自定义验证规则
        form.verify({
            title: function (value) {
                if (value.length < 2) {
                    return '用户名至少得2个字符啊';
                }
            }
            , pass: [
                /^[\S]{6,12}$/
                , '密码必须6到12位，且不能出现空格'
            ]
            , content: function (value) {
                layedit.sync(editIndex);
            }
        });

        //监听指定开关
        form.on('switch(switchTest)', function (data) {
            layer.msg('开关checked：' + (this.checked ? 'true' : 'false'), {
                offset: '6px'
            });
            layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
        });

        //监听提交
        form.on('submit(demo1)', function (data) {


            var industryObj = $('input[name="type"]');
            var check_val = [];
            for(k in industryObj){
                if(industryObj[k].checked){
                    check_val.push(industryObj[k].value);
                }
            }
            data.field.type = check_val;
            var user1 = JSON.stringify(data.field);
           /* layer.alert(JSON.stringify(data.field), {
                title: '最终的提交信息'
            })
*/

             $.ajax({
                    url:'../../user/realUpdate',
                    data:{user1:user1},
                    success:function (msg) {
                        layer.alert(msg);
                    },
                    error:function () {
                        layer.alert('failed');
                    }

                })
            return false;
        });




    });
</script>

</body>
</html>